package com.iss.apartmentmanage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.iss.apartmentmanage.entity.UserInfo;
import com.iss.apartmentmanage.model.UserWithUserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserInfoMapper extends BaseMapper<UserInfo> {
    @Update("<script> update user_info set is_used=#{isUser} where id in " +
            "       <foreach collection=\"id\" item=\"id\" separator=\",\" open=\"(\" close=\")\">" +
            "          #{id}" +
            "       </foreach>" +
            "</script>")
    Integer updateIsUsedByUinfoIds(String[] id,int isUser);

    @Select("select user.id,user.u_name,user.u_pwd,user.u_phone,user.`status`,user.isvip,\n" +
            "user_info.uinfo_name,user_info.uinfo_gender,user_info.uinfo_idcard,user_info.uinfo_email,\n" +
            "user_info.create_time,user_info.update_time,user_info.deleted,user_info.is_used,user_info.belong_area_id\n" +
            "from user inner join user_info on user.id=user_info.userinfo_id \n" +
            "where user.u_name=#{uName}")
    UserWithUserInfo getUserinfoByUsername(String uName);

    @Select("select user.id,user.u_name,user.u_pwd,user_info.userinfo_id\n" +
            "from user inner join user_info \n" +
            "on user.id=user_info.userinfo_id where user.id=#{id}")
    UserWithUserInfo getUserInfoUnameAndUpwdByUid(UserWithUserInfo uId);
}

